home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / C Demos / MultiSkel / MultiSkel.c < prev    next >
Text File  |  1995-03-21  |  5KB  |  217 lines

  1. /*
  2.  * Should add menu hook routine to dim Close item when no windows are active.
  3.  *
  4.  * MultiSkel - TransSkel multiple-window demonstration main module
  5.  *
  6.  * This module performs setup and termination operations, installs
  7.  * the window and menu handlers, and processes menu item selections.
  8.  *
  9.  * There are four window handlers in this demonstration.  The code
  10.  * for each handler is in its own module.
  11.  *
  12.  * Help Window        Scrollable non-editable text window
  13.  * Edit Window        Non-scrollable editable text window
  14.  * Zoom Window        Non-manipulable graphics display window
  15.  * Region Window    Manipulable graphics display window
  16.  *
  17.  * 21 Apr 88 Paul DuBois
  18.  * 29 Jan 89 Version 1.01
  19.  * - Conversion for TransSkel 2.0.
  20.  * 12 Jan 91 Version 1.02
  21.  * - Conversion for TransSkel 3.00.
  22.  * 05 Jun 93 Version 1.03
  23.  * - Conversion for THINK C 6.0.
  24.  * 15 Feb 94
  25.  * - Numerous minor revisions.
  26.  * 21 Feb 94
  27.  * - Updated for TransSkel 3.11.
  28.  * 04 Nov 94
  29.  * - Updated for TransSkel 3.18 (Support for Universal headers, PowerPC,
  30.  * Metrowerks).
  31.  * 21 Mar 95
  32.  * - Updated for TransSkel 3.19.
  33.  */
  34.  
  35. # include    "TransSkel.h"
  36.  
  37. # include    "MultiSkel.h"
  38.  
  39.  
  40. /* File menu item numbers */
  41.  
  42. typedef enum {
  43.     open = 1,
  44.     close,
  45.     /* --- */
  46.     quit = 4
  47. } fileItems;
  48.  
  49.  
  50. WindowPtr    helpWind;
  51. WindowPtr    editWind;
  52. WindowPtr    zoomWind;
  53. WindowPtr    rgnWind;
  54.  
  55.  
  56. /*
  57.  * Menu handles.  There isn't any Apple menu here, since TransSkel will
  58.  * be told to handle it itself.
  59.  */
  60.  
  61. static MenuHandle    fileMenu;
  62. MenuHandle            editMenu;
  63.  
  64. static RgnHandle    oldClip;
  65.  
  66.  
  67. /*
  68.  * Miscellaneous routines
  69.  * These take care of drawing the grow box and the line along
  70.  * the right edge of the window, and of setting and resetting the clip
  71.  * region to disallow drawing in that right edge by the other drawing
  72.  * routines.
  73.  */
  74.  
  75.  
  76. void
  77. DrawGrowBox (WindowPtr wind)
  78. {
  79. Rect        r;
  80. RgnHandle    oldClip;
  81.  
  82.     r = wind->portRect;
  83.     r.left = r.right - 15;        /* draw only along right edge */
  84.     oldClip = NewRgn ();
  85.     GetClip (oldClip);
  86.     ClipRect (&r);
  87.     DrawGrowIcon (wind);
  88.     SetClip (oldClip);
  89.     DisposeRgn (oldClip);
  90. }
  91.  
  92.  
  93. void
  94. SetWindClip (WindowPtr wind)
  95. {
  96. Rect        r;
  97.  
  98.     r = wind->portRect;
  99.     r.right -= 15;        /* don't draw along right edge */
  100.     oldClip = NewRgn ();
  101.     GetClip (oldClip);
  102.     ClipRect (&r);
  103. }
  104.  
  105.  
  106. void
  107. ResetWindClip (void)
  108. {
  109.     SetClip (oldClip);
  110.     DisposeRgn (oldClip);
  111. }
  112.  
  113.  
  114. /*
  115.  * Show a window if it's not visible.  Select the window FIRST, then
  116.  * show it, so that it comes up in front.  Otherwise it will be drawn
  117.  * in back then brought to the front, which is ugly.
  118.  *
  119.  * The test for visibility must be done carefully:  the window manager
  120.  * stores 255 and 0 for true and false, not real boolean values.
  121.  */
  122.  
  123. static void
  124. MyShowWindow (WindowPtr wind)
  125. {
  126.  
  127.     if (((WindowPeek) wind)->visible == false)
  128.     {
  129.         SelectWindow (wind);
  130.         ShowWindow (wind);
  131.     }
  132. }
  133.  
  134.  
  135. /*
  136.  * Handle selection of About MultiSkel... item from Apple menu
  137.  */
  138.  
  139. static pascal void
  140. DoAppleMenu (short item)
  141. {
  142.     (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
  143.                                         skelPositionOnParentDevice);
  144.     SkelRmveDlogFilter ();
  145. }
  146.  
  147.  
  148. /*
  149.  * Process selection from File menu.
  150.  *
  151.  * Open        Make all four windows visible
  152.  * Close    Hide the frontmost window.  If it belongs to a desk accessory,
  153.  *            close the accessory.
  154.  * Quit        Request a halt by calling SkelHalt().  This makes SkelMain
  155.  *            return.
  156.  */
  157.  
  158. static pascal void
  159. DoFileMenu (short item)
  160. {
  161.     switch (item)
  162.     {
  163.         case open:
  164.             MyShowWindow (rgnWind);
  165.             MyShowWindow (zoomWind);
  166.             MyShowWindow (editWind);
  167.             MyShowWindow (helpWind);
  168.             break;
  169.  
  170.         case close:
  171.             SkelClose (FrontWindow ());
  172.             break;
  173.  
  174.         case quit:
  175.             SkelStopEventLoop ();        /* request halt */
  176.             break;
  177.     }
  178. }
  179.  
  180.  
  181. /*
  182.  * Initialize menus.  Tell TransSkel to process the Apple menu automatically,
  183.  * and associate the proper procedures with the File and Edit menus.
  184.  * The Edit menu is enabled only when the Edit is frontmost.
  185.  *
  186.  * \311 = ellipsis character
  187.  */
  188.  
  189. static void
  190. SetUpMenus (void)
  191. {
  192.     SkelApple ((StringPtr) "\pAbout MultiSkel\311", DoAppleMenu);
  193.     fileMenu = GetMenu (fileMenuRes);
  194.     (void) SkelMenu (fileMenu, DoFileMenu, nil, false, false);
  195.     editMenu = GetMenu (editMenuRes);
  196.     (void) SkelMenu (editMenu, EditWindEditMenu, nil, false, true);
  197. }
  198.  
  199.  
  200. int
  201. main (void)
  202. {
  203. long    f, b;
  204.  
  205.     SkelInit ((SkelInitParamsPtr) nil);
  206.     SkelGetWaitTimes (&f, &b);
  207.     b = f;
  208.     SkelSetWaitTimes (f, b);
  209.     SetUpMenus ();            /* install menu handlers */
  210.     RgnWindInit ();            /* install window handlers  */
  211.     ZoomWindInit ();
  212.     EditWindInit ();
  213.     HelpWindInit ();
  214.     SkelEventLoop ();        /* process events */
  215.     SkelCleanup ();            /* throw away windows and menus */
  216. }
  217.